const request = (url, data = {}, method = "get") => {

	let timer = setTimeout(() => {
		uni.showLoading({
			title: '加载中'
		});
	}, 300);

	let request =
		() => {
			try {
				return new Promise((resolve, reject) => {
					uni.request({
						url: "http://112.74.76.116:5000" + url,
						data,
						method,
						header: {
							'Content-Type': 'application/json',
							// 'Authorization': localStorage.token
							'Authorization': uni.getStorageSync('token'),

						},
						dataType: "json",
					}).then(res => {
						uni.hideLoading();
						clearTimeout(timer);
						resolve(res);
					}).catch(err => {
						uni.showModal({
							content:"网络错误,请刷新或重新进入"
						})
						throw err;
					})
				})
			} catch (e) {
				uni.showModal({
					content:"网络错误,请刷新或重新进入"
				})
				throw err;
				request();
			}
		}



	return request();


}
// let BaseConfig = axios.create({
//     baseURL: "http://112.74.76.116:5000",
//     timeout: 5000,
//     headers: {
//         'Content-Type': 'application/json'
//     }
// });

export default request;
// uni.showLoading({
// 		title: '加载中'
// 	});
// 	// uni.hideLoading();
// 	return uni.request({
// 		url: "http://112.74.76.116:5000" + url,
// 		data,
// 		method,
// 		headers: {
// 			'Content-Type': 'application/json',
// 			'Authorization': uni.getStorage({
// 				key: 'token'
// 			})
// 		},
// 	})
